'use strict';

describe 'modal controllers', ()->

  beforeEach(module('UCX.Cmis'))
  describe 'LoadingController', ()->
    $scope = {}
    it '测试loading ', inject ($controller)->
      $scope = {}
      content = 'xxxxxxxxx'
      ctrl = $controller('LoadingController', {$scope:$scope, content:content})
      expect($scope.content).toEqual(content)
      expect(ctrl).toBeDefined()

  describe 'UploadDrnCtrl', ()->
    $scope = {}
    dropFile = null
    depends = {
      $scope:$scope,
      $uibModalInstance:{},
      dropFile: dropFile,
      Loading: {},
      CmisService: {},
      folder: {},
      Utils: {},
      $translate: {},
      parentScope: {},
      $timeout: {},
      UploadQueue: {}
    }
    it '测试 isDisabled true', inject ($controller)->
      uploadDrm = $controller('UploadDrnCtrl', depends)
      expect($scope.isDisabled()).toEqual(true)

    it '测试 isDisabled true', inject ($controller)->
      uploadDrm = $controller('UploadDrnCtrl', depends)
      $scope.file = 11
      expect($scope.isDisabled()).toEqual(false)



  describe 'CreateFolderCtrl', ()->
    depends = {
      $scope:{}
      $uibModalInstance:{}
    }
    it '测试 isDisabled true', inject ($controller)->
      ctrl = $controller('CreateFolderCtrl', depends)
      expect(ctrl).toBeDefined()



  describe 'createInviteModal', ()->
    $scope = {}
    depends = {
      $scope:$scope
      $uibModalInstance :{}
      document:{}
      sendToOwner:{}
      sending:{}
      Utils:{
        warning: (msg)->
          msg
      }
      isOwner: true
      CmisService:{}
      ModelService:{}
    }
    it '测试 delete', inject ($controller)->
      ctrl = $controller('createInviteModal', depends)
      $scope.emails = [1,2,3]
      $scope.delete(1)
      expect($scope.emails).toEqual([1,3])

    it '测试 addNewEmail', inject ($controller)->
      ctrl = $controller('createInviteModal', depends)
      email = '123@qq.com'
      $scope.newEmail = email
      $scope.addNewEmail()
      expect($scope.newEmail).toEqual('')
      expect($scope.emails[0].emailAddress).toEqual(email)

      invalidEmail = '1111'
      $scope.newEmail = invalidEmail
      expect($scope.addNewEmail()).toEqual('Invalid Email')
      $scope.newEmail = ''
      expect($scope.addNewEmail()).toEqual('Email Not Null')

    it 'getEmailList', inject ($controller)->
      ctrl = $controller('createInviteModal', depends)
      $scope.emails = [
        {
          emailAddress:'11'
        },
        {
          emailAddress:'222'
        },
        {
          emailAddress:'333'
        },
        {
          emailAddress: ''
        }
      ]
      $scope.newEmail = '44'
      expect($scope.getEmailList()).toEqual(['11','222','333','44'])

    it 'isValid', inject ($controller)->
      ctrl = $controller('createInviteModal', depends)
      $scope.emails = [
        emailAddress: '11@qq.com'
      ]
      $scope.newEmail = ''
      expect($scope.isValid()).toEqual(true)

      $scope.emails = [
        emailAddress: '11qq.com'
      ]
      $scope.newEmail = '11@qq.com'
      expect($scope.isValid()).toEqual(false)

      $scope.emails = [
        emailAddress: ''
      ]
      $scope.newEmail = ''
      expect($scope.isValid()).toEqual(false)


  describe 'ConfirmController', ()->
    depends = {
      $scope: {}
      $uibModalInstance: {}
      content: {}
    }
    it 'toBeDefined', inject ($controller)->
      ctrl = $controller('ConfirmController', depends)
      expect(ctrl).toBeDefined()

#  describe 'uploadNewVersionCtrl', ()->
#    depends = {
#      $scope:{}
#      $uibModalInstance:{}
#      parentScope:{}
#      rootScope:{}
#      $translate:{}
#      Utils:{}
#      CmisService:{}
#      Loading:{}
#      UploadQueue: {}
#    }
#    it 'toBeDefined', inject ($controller)->
#      ctrl = $controller('uploadNewVersionCtrl', depends)
#      expect(ctrl).toBeDefined()

#  describe 'userNotAllowedUpload', ()->
#    depends = {
#      $scope:{}
#      $uibModalInstance:{}
#    }
#    it 'toBeDefined', inject ($controller)->
#      ctrl = $controller('userNotAllowedUpload', depends)
#      expect(ctrl).toBeDefined()

  describe 'createProgressBarModal', ()->
    $scope = {}
    depends = {
      $scope:$scope
      $uibModalInstance:{}
      rootScope:{}
      queueFiles:{}
      UploadQueue:{
        uploading: false
        barIsOpen: false

      }
    }
    it 'toBeDefined', inject ($controller)->
      ctrl = $controller('createProgressBarModal', depends)
      expect(ctrl).toBeDefined()

    it 'isUploading', inject ($controller)->
      ctrl = $controller('createProgressBarModal', depends)
      expect($scope.isUploading()).toEqual(false)
      expect($scope.isBarOpen()).toEqual(false)
      $scope.toggleQueue()
      expect($scope.isBarOpen()).toEqual(true)

  describe 'sharedFileModal', ()->
    $scope = {}
    depends = {
      $scope:$scope
      $uibModalInstance:{}
      scope:{}
      file:{}
#      ApiService:{}
#      $timeout:{}
      $q:{}
      Utils:{}
      $translate:{}
    }
    it 'toBeDefined', inject ($controller)->
      ctrl = $controller('sharedFileModal', depends)
      expect(ctrl).toBeDefined()

    it '$scope.getAppSharedApiLink link should be the same as provide', inject ($controller)->
      ctrl = $controller('sharedFileModal', depends)
      $scope.loading=true
      expect($scope.getAppSharedApiLink('google')).toEqual('https://plus.google.com/share?url=')
      expect($scope.getAppSharedApiLink('facebook')).toEqual('https://www.facebook.com/share.php?u=')
      expect($scope.getAppSharedApiLink('twitter')).toEqual('https://twitter.com/intent/tweet?text=')
      expect($scope.getAppSharedApiLink('linkedin')).toEqual('https://www.linkedin.com/shareArticle?mini=true&url=')
      expect($scope.getAppSharedApiLink('weibo')).toEqual('http://service.weibo.com/share/share.php?title=')
#    it 'if file has sharedLink qr should init and show the qr-code', inject ($controller)->
#      ctrl = $controller('sharedFileModal', depends)
#      $scope.sharedLink = 'http://www.baidu.com/'
#      content = $('#qrcode').html();
#      expect($('#qrcode').html()).toEqual('123')



